package com.vinyl.android.chinese.fragment;


import com.vinyl.android.chinese.R;
import com.vinyl.android.chinese.fragment.*;
import com.vinyl.android.chinese.manager.TabManager;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.widget.TabHost;
import android.widget.TextView;
 
public class MainFragment extends FragmentActivity implements TabHost.OnTabChangeListener {
    TabHost mTabHost;
    TabManager mTabManager;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_fragment);
         
        mTabHost = (TabHost) findViewById(android.R.id.tabhost);
        mTabHost.setup();

        
        mTabManager = new TabManager(this, mTabHost, R.id.realtabcontent);
        mTabManager.addTab(mTabHost.newTabSpec("home").setIndicator("", getResources().getDrawable(R.drawable.btn_home)),
                EmptyFragment.class, null);
        mTabManager.addTab(mTabHost.newTabSpec("tip").setIndicator("", getResources().getDrawable(R.drawable.btn_tip)),
                TourtipFragment.class, null);
        mTabManager.addTab(mTabHost.newTabSpec("search").setIndicator("", getResources().getDrawable(R.drawable.btn_search)),
                SearchFragment.class, null);
        mTabManager.addTab(mTabHost.newTabSpec("favorite").setIndicator("", getResources().getDrawable(R.drawable.btn_favorite)),
                FavoriteFragment.class, null);
        mTabManager.addTab(mTabHost.newTabSpec("info").setIndicator("", getResources().getDrawable(R.drawable.btn_info)),
                InfoFragment.class, null);

        mTabHost.setOnTabChangedListener(this);
        mTabHost.setCurrentTabByTag("tip"); 
        Log.d("MainActivity", "onCreate");
    }

	public void onTabChanged(String tabId) {
		if ("home".equals(tabId)) {
			finish();
			return;
		}
		mTabManager.onTabChanged(tabId);
		
		Log.d("MainActivity", "onTabChange");
		TextView tv = (TextView)mTabHost.findViewById(R.id.title_text);
		tv.setText(tabId);
	}
	
}